<?php

include("header.php");
$searchvalues=null;
$restoname=null;
$post=null;

if(isset($_POST["searchkey"])){
	$searchvalues=$_POST["searchkey"];
	if(is_numeric($searchvalues)&&strlen($searchvalues)){
		$post=$searchvalues;
		if(preg_match("/750/", $post)){
			$post = substr($post,3, 2) . "ème à Paris";
		}
	}else{
		$restoname=$searchvalues;
	}
}else{
	redirect("index.php");
}
?>
<?php

	// Connect to server and select databse.
	// Connect to server and select databse.
	$db = Database::obtain(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
	$db->connect();

	if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; };
	if (isset($_GET["sort"])) { $order_col  = $_GET["sort"]; } else { $order_col='RESTO_NAME_$_lang'; };

	if ($page<0 || ((int)$page != $page)) {
		$message  = 'Invalid page number: ' .$page . "\n";
		die($message);
	}

	$start_from = ($page-1) * 15;
	$sql = "SELECT info_resto.RESTO_ID AS restoid, info_resto.RESTO_NAME_$_lang AS restoname, info_resto.RESTO_NATION as nationid, info_resto.RESTO_TYPE_ID as typeid,
		info_resto.INTRO_PIC AS pic, info_resto.RESTO_INTRO_$_lang AS resto_intro,
		info_resto.RESTO_ADDR AS resto_addr,HAS_COUPON,HAS_RESERV FROM info_resto
		WHERE info_resto.RESTO_ADDR like '%$searchvalues%' OR info_resto.RESTO_NAME_FR like '%$searchvalues%'
		OR info_resto.RESTO_NAME_ARB like '%$searchvalues%'";
		
	$rs_count_result = $db->query_first ("SELECT COUNT(RESTO_ID) as total FROM info_resto	
	WHERE info_resto.RESTO_ADDR like '%$searchvalues%' OR info_resto.RESTO_NAME_FR like '%$searchvalues%'
		OR info_resto.RESTO_NAME_ARB like '%$searchvalues%'");
	$rs_result = mysql_query ($sql);

	
	$total_records = $rs_count_result['total'];
	$total_pages = ceil($total_records / 15);
	// Check result
	// This shows the actual query sent to MySQL, and the error. Useful for debugging.
	if (!$rs_result) {
		$message  = 'Invalid query: ' . mysql_error() . "\n";
		$message .= 'Whole query: ' . $sql;
		die($message);
	}
	$db->close();
	?>
<div class="contactBg">
 <div class="contactDeit fl">
  <div class="contact noLine">
    <ul>
      <li><?php if($_lang==FR){ echo "Accueil";} else if($_lang==ARB){echo "الصفحة الرئيسية";}?>></li>
      <li><?php if(!is_null($post)) {echo $post;} else {echo $searchvalues;} ?> :</li>
      <li>nous avons trouvé plus de <?php echo $total_records; if($total_records=='0'||$totoal_records=='1')echo " réponse !"; else echo " réponses !"?></li>
    </ul>
  </div>
  <!--contact end of-->
	<?php
		while ($row = mysql_fetch_assoc($rs_result)) {
			$infor = strip_tags($row['resto_intro']);
	?>
	  <div class="searchList">
		<p class="fl"><a href="diningHallinfr.php?restoid=<?php echo $row['restoid']; ?>&nationid=<?php echo $row['nationid'];?>&typeid=<?php echo $row['typeid'];?>">
			<img src=<?php echo $row['pic']; ?> width="250" height="112" alt="" /></a></p>
		<dl class="fl">
		  <dt><a href="diningHallinfr.php?restoid=<?php echo $row['restoid']; ?>&nationid=<?php echo $row['nationid'];?>&typeid=<?php echo $row['typeid'];?>" style="color:#000"><?php echo $row['restoname']; ?></a> </dt>
		  <dd class="searchDd"><?php echo $row['resto_addr']; ?></dd>
		  <dd><?php echo cut_str($infor,220); ?>...
		  <a href="diningHallinfr.php?restoid=<?php echo $row['restoid']; ?>&nationid=<?php echo $row['nationid'];?>&typeid=<?php echo $row['typeid'];?>" class="red">Suite</a></dd>
		</dl>
		<?php if(ord($row['HAS_RESERV'])){?>
		<a href="reserver.php?restoid=<?php echo $row['restoid']; ?>" class="reserver top30"></a>
		<?php }?>
		<?php if(ord($row['HAS_COUPON'])){?>
		<a href="coupon.php?restoid=<?php echo $row['restoid']; ?>" class="coupon top80"></a>
		<?php }?>
	  </div>
	<?php
	};
	?>
  <!--searchList end of-->
  </div>
</div>
<!--contactBg end of-->
<?php
include("foot.php");
?>

